package com.neighbor.neighborhooduser.controller;

import com.neighbor.neighborhooduser.pojo.PointsRecords;
import com.neighbor.neighborhooduser.service.IPointsRecordsService;
import com.neighbor.neighborhooduser.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 用户积分记录表 前端控制器
 * </p>
 *
 * @author song
 * @since 2025-09-22 09:13:04
 */
@RestController
@RequestMapping("/pointsRecords")
public class PointsRecordsController {
    @Autowired
    IPointsRecordsService pointsRecordsService;

    // 根据用户id 得到对应的积分记录
    @GetMapping("/pointsRecord/{userId}")
    ResponseMsg pointsRecord(@PathVariable Integer userId){
        return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "积分记录查询成功", pointsRecordsService.getPointsRecordByUserId(userId));
    }

    // 增加 积分记录
    @RequestMapping("/addPointsRecords")
    ResponseMsg addPointsRecords(@RequestBody PointsRecords pointsRecords){
        pointsRecords.setCreatedAt(new Date());
        System.out.println("兑换记录数据: " + pointsRecords);
        return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "增加兑换记录成功", pointsRecordsService.save(pointsRecords));
    }
}
